package com.charley.icloud.blog;

import lombok.extern.slf4j.Slf4j;
//import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 启动入口，运行此main方法，即可启动项目
 */
@Slf4j
@EnableDiscoveryClient // 开启Consul服务发现支持
@SpringBootApplication
public class BlogMainAppStarter extends SpringBootServletInitializer {

    public static void main(String[] args) throws UnknownHostException {
        ApplicationContext application = SpringApplication.run(BlogMainAppStarter.class, args);
        Environment environment = application.getEnvironment();
        String ipAddr = InetAddress.getLocalHost().getHostAddress();
        String port = environment.getProperty("server.port");
        String path = environment.getProperty("server.servlet.context-path");
        String appName = environment.getProperty("spring.application.name");
        if(path == null) path="";
        log.info("\n---------------------------------------------------------------------------------------\n" +
                "Application '{}' is running! Access URLs:\t\n" +
                "Local: \t\thttp://localhost:" + port + path + "/\n" +
                "External: \thttp://" + ipAddr + ":" + port + path + "/\n" +
                "Druid: \t\thttp://" + ipAddr + ":" + port + path + "/druid/login.html\n" +
                "Consul: \thttp://localhost:8500\n" +
                "Doc: \t\thttp://" + ipAddr + ":" + port + path + "/doc.html\n" +
                "------------------------------ 启动成功 By charley -------------------------------------\n",appName);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(BlogMainAppStarter.class);
    }
}
